package ru.ds.selenium.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class AddMoviePage extends InternalPage {
	public AddMoviePage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(xpath = "//input[@name='imdbid']")
	private WebElement imdbInput;
	
	@FindBy(xpath = "//input[@name='name']")
	private WebElement nameInput;
	
	@FindBy(xpath = "//input[@name='year']")
	private WebElement yearInput;
	
	@FindBy(xpath = "//textarea[@name='notes']")
	private WebElement notesTextArea;
	
	@FindBy(xpath = "//input[@id='submit']")
	private WebElement submitButton;
	
	
	public AddMoviePage setImdbId(String id){
		imdbInput.sendKeys(id);
		return this;
	}
	
	public AddMoviePage setTitle(String title){
		nameInput.sendKeys(title);
		return this;
	}
	
	public AddMoviePage setYear(String year){
		yearInput.sendKeys(year);
		return this;
	}
	
	public AddMoviePage setNotes(String notes){
		notesTextArea.sendKeys(notes);
		return this;
	}
	
	public void clickSubmitButton() {
		submitButton.click();
	}
	
	public AddMoviePage ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//form[@id='updateform']")));
		return this;
	}	

}
